<template>
    <div>
        <!-- 顶部滑动条区域 -->
        <div id="slider" class="mui-slider ">
            <div id="sliderSegmentedControl" class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted">
                <div class="mui-scroll">
                    <a :class="['mui-control-item',item.id === 0 ? 'mui-active' : '' ]" href="#item1mobile" v-for="item in photolist" :key="item.id" @click="getPhotos(item.id)">
                        {{item.title}}
                    </a>
                </div>
            </div>
        </div>
        <!-- 图片列表 -->
        <ul class="photolist">
            <router-link v-for="item in photos" :key="item.id" :to="'/home/photoinfo/'+item.id" tag="li">
                <img v-lazy.container="item.img_url">
                <div>
                    <h3>{{item.title}}</h3>
                    <p>{{item.zhaiyao}}</p>
                </div>
            </router-link>
        </ul>
    </div>
</template>
<script>
    import mui from '../../../static/js/mui.min.js'
    
    export default {
        data() {
            return {
                photolist : [],
                photos: []
            }
        },
        methods: {
            getPhotoList() {
                this.$http.get('http://vue.studyit.io/api/getimgcategory').then(result=>{
                    //console.log(result.body.message);
                    this.photolist = result.body.message;
                });
            },
            getPhotos(id=18) {
                this.$http.get('http://vue.studyit.io/api/getimages/'+id).then(result=>{
                    this.photos = result.body.message;
                    // console.log(this.photos);
                });
            }
        },
        created() {
            this.getPhotoList();
            this.getPhotos();
        },
        // 当组件中的dom结构渲染好，并放到页面中后，会执行这个钩子函数
        mounted() {
            // 数据挂载之后
            mui('.mui-scroll-wrapper').scroll({
                deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
            });
        }
    }
</script>
<style lang="less" scoped>
*{
    touch-action: pan-y;
}
.photolist{
    margin:0;
    padding:0;
    list-style: none;
    li{
        background: #eee;
        text-align: center;
        margin: 10px;
        position: relative;
        div{
            position: absolute;
            left:0;
            bottom:0;
            background: rgba(0,0,0,.5);
            color:#fff;
            text-align: left;
            padding:5px;
            h3{
                font-size: 14px;
            }
            p{
                color: #fff;
            }
        }
        img{
            width:100%;
        }
        image[lazy="loading"] {
            width: 40px;
            height: 300px;
            margin: auto;
        }
    }
}
</style>
